package com.norra.client.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.norra.base.api.ApiCallback
import com.norra.base.api.HError
import com.norra.base.api.WebService
import com.norra.base.api.entity.DeviceResponse
import com.norra.base.viewmodel.NetworkResource

class DeviceViewModel : ViewModel() {

    public fun getDeviceList(): LiveData<NetworkResource<DeviceResponse>> {

        val liveData = MutableLiveData<NetworkResource<DeviceResponse>>()
        WebService.get().getMyDeviceList().enqueue(object : ApiCallback<DeviceResponse> {
            override fun onSuccess(response: DeviceResponse) {
                liveData.postValue(NetworkResource.success(response))
            }

            override fun onError(error: HError) {
                liveData.postValue(NetworkResource.error(error))
            }
        })
        return liveData
    }
}